package graph.drawings;

public class Bound {

	// x1 < x2 and y1 < y2
	protected double x1, y1, x2, y2;

	public Bound() {
		x1 = 0;
		x2 = 0;
		y1 = 0;
		y2 = 0;
	}
	
	public Bound(double x1, double y1, double x2, double y2) {
		updateAndVerifyBound(x1, y1, x2, y2);
	}

	public void setBound(double x1, double y1, double x2, double y2) {
		updateAndVerifyBound(x1, y1, x2, y2);
	}
	
	public double getX1() {
		return this.x1;
	}
	public double getX2() {
		return this.x2;
	}
	public double getY1() {
		return this.y1;
	}
	public double getY2() {
		return this.y2;
	}
	
	
	public double Width() {
		return Math.abs(x2 - x1);
	}

	public double Height() {
		return Math.abs(y2 - y1);
	}

	public boolean ContainsPoint(double x, double y) {
		if ((x < x1) || (x > x2))
			return false;
		if ((y < y1) || (y > y2))
			return false;

		return true;
	}

	private void updateAndVerifyBound(double x1, double y1, double x2, double y2) {
		this.x1 = Math.min(x1, x2);
		this.x2 = Math.max(x1, x2);
		this.y1 = Math.min(y1, y2);
		this.y2 = Math.max(y1, y2);
	}
}
